<%-- 
    Document   : index
    Created on : 24-mag-2011, 15.45.46
    Author     : dav
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" rel="stylesheet" type="text/css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Biblioteca</title>
    </head>
    <body>
        <% 
            if(session.getAttribute("username")==null || session.getAttribute("ruolo").equals("u")){
                      %>
                     <script type="text/javascript">

                         alert("Non autorizzato");

                         window.location.href="index.jsp";

                     </script>
            <%
            }
        %>
        <div id="container">
        <div id="header">Biblioteca Online</div>

            <div id="menu">
                <jsp:include page="menu.jsp" flush="true"/>                        
            </div>
            
            <div id="content">
                <center><h2>Inserimento nuovo libro</h2></center>
                <form action="cGestore?action=i" method="POST" onsubmit="return controllo()">
                    <center> 
                    <table>
                        <tr>
                            <td>
                                Titolo : 
                            </td>
                            <td>
                                <input type="text" name="titolo" id="a"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Autore : 
                            </td>
                            <td>
                                <input type="text" name="autore" id="b"></input>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Editore : 
                            </td>
                            <td>
                                <input type="text" name="editore" id="c"></input>
                            </td>
                        </tr>
                        <tr>    
                            <td>
                                Anno : 
                            </td>
                            <td>
                                <input type="text" name="anno" id="d"></input>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"><center><input type="submit" value="Inserisci"></center></td>
                        </tr>
                    </table>
                    </center>
                    <script type="text/javascript">
                        function controllo(){
                            var a = document.getElementById("a").value;
                            var b = document.getElementById("b").value;
                            var c = document.getElementById("c").value;
                            var d = document.getElementById("d").value;
                            
                            if(a=="" || b=="" || c=="" || d==""){
                                alert("Inserire tutti i campi")
                                return false;
                            }else {
                                var e = parseInt(d);
                                if(e.toString()=="NaN"){
                                    alert("Anno deve essere un numero")
                                    return false;
                                }
                                return true;
                            }
                    return false;    
                    }
                    </script>
                    <jsp:include page="inserito.jsp" flush="true"/>
            </div>    
        </div>
        
    </body>
</html>
